
public class Strategy {

	public static interface FlyBehavior {
		public void fly();
	}
	public static class FlyWithWings implements FlyBehavior{
		public void fly() {
			System.out.println("Im flying");
		}
	}
	public static class FlyNoWings implements FlyBehavior{
		public void fly() {
			System.out.println("Cannot fly");
		}
	}
	
	public static interface QuackBehavior {
		public void quack();
	}
	public static class Quack implements QuackBehavior{
		public void quack() {
			System.out.println("Quack Quack");
		}
	}
	public static class Squeak implements QuackBehavior{
		public void quack() {
			System.out.println("Squeak");
		}
	}
	
	public static abstract class Duck {
		FlyBehavior flyBehavior;
		QuackBehavior quackBehavior;
		public Duck() {
			display();
		}
		void performFly() {
			flyBehavior.fly();
		}
		void performQuack() {
			quackBehavior.quack();
		}
		void swim() {
			System.out.println("All ducks swim!!");
		}
		void setFlyBehavior(FlyBehavior fb) {
			flyBehavior = fb;
		}
		void setQuackBehavior(QuackBehavior qb) {
			quackBehavior = qb;
		}
		public void display(){};
	}
	
	public static class MallardDuck extends Duck {
		public MallardDuck() {
			flyBehavior = new FlyWithWings();
			quackBehavior = new Quack();
		}
		public void display(){
			System.out.println("Im a real Mallard Duck");
		}
	}
	public static class ModelDuck extends Duck {
		public ModelDuck() {
			flyBehavior = new FlyNoWings();
			quackBehavior = new Quack();
		}
		public void display(){
			System.out.println("Im a model Duck");
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Duck mallard = new MallardDuck();
		mallard.performFly();
		mallard.performQuack();
		mallard.setFlyBehavior(new FlyNoWings());
		mallard.performFly();
		Duck model = new ModelDuck();
		model.performFly();
		model.performQuack();
	}
}
